home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Other / mCD / Source / scsi_cd.subproj / ListScsi.m < prev    next >
Encoding:
Text File  |  1994-03-19  |  3.5 KB  |  123 lines

  1. /*
  2.  * ListScsi.m
  3.  *    - This, and the main routine it calls (do_inquiryall), were
  4.  *    written by Garance Alistair Drosehn/Mar 1994.  Note that
  5.  *    do_inquiryall may not be safe to call at all times.  For the
  6.  *    most part this works fine for me, but occasionally it will
  7.  *    totally lock up my machine for a minute or so.  Thus I do
  8.  *    not recommend it's use (until someone can fix do_inquiryall).
  9.  */
  10.  
  11. #import <ctype.h>
  12. #import "ListScsi.h"
  13.  
  14. @implementation ListScsi
  15.  
  16. - init
  17. {
  18.     int scsiIndex, diskIndex;
  19.     
  20.     do_inquiryall( INQ_ALL_MAX_SCSI_CNT, &inquireAllResult, &inquire_Ereply);
  21.  
  22.     diskIndex = 0;
  23.     for(scsiIndex = 0; scsiIndex < inquireAllResult.maxScsiCount;
  24.                    scsiIndex++) {
  25.     if ( inquireAllResult.scsiArray[scsiIndex].deviceNumber >= 0 ) {
  26.         /* there is a device with this SCSI ID index, remember
  27.          * the SCSI id and increment the disk index counter
  28.          */
  29.         mapDiskToScsiId[diskIndex] = scsiIndex;
  30.         diskIndex++;
  31.         }
  32.     }        /* end for(scsiIndex =... */
  33.  
  34.     /* fill up the rest of the DiskToScsiId array */
  35.     for( ; diskIndex < INQ_ALL_MAX_SCSI_CNT; diskIndex++) {
  36.     mapDiskToScsiId[diskIndex] = -1;
  37.     }
  38.     
  39.     return self;
  40. }
  41.  
  42. - (int) _scsiIndex:(int) devIndex
  43. {
  44.     if ((devIndex < 0) || (devIndex >= INQ_ALL_MAX_SCSI_CNT)) {
  45.     return -1;
  46.     }
  47.     return mapDiskToScsiId[devIndex];
  48. }
  49.  
  50. - (int) getTypeOfDev:(int) devNumber
  51. {
  52.     struct inquiry_reply *mInq;
  53.     int scsiIndex = [self _scsiIndex:devNumber];
  54.  
  55.     if (scsiIndex < 0) return DEVTYPE_NOTPRESENT;
  56.  
  57.     mInq = &(inquireAllResult.scsiArray[scsiIndex].inqResult);
  58.     return mInq->ir_devicetype;
  59. }
  60.  
  61. - (int) getTypeOfDev:(int) devNumber retCharDescription:(char *)devStr
  62. {
  63.     struct inquiry_reply *mInq;
  64.     char   tempStr[20];
  65.     int    charIndex;
  66.     int    scsiIndex = [self _scsiIndex:devNumber];
  67.  
  68.     if (scsiIndex < 0) {
  69.     sprintf (devStr, "sd%d - no device attached", devNumber);
  70.     return DEVTYPE_NOTPRESENT;
  71.     }
  72.  
  73.     mInq = &(inquireAllResult.scsiArray[scsiIndex].inqResult);
  74.     sprintf (devStr, "sd%d [%d]: ", devNumber, scsiIndex);
  75.  
  76.     /* tack on the vendor string, trimmed and prettified */
  77.     *tempStr = '\0';
  78.     strncat(tempStr, mInq->ir_vendorid, sizeof(mInq->ir_vendorid));
  79.     tempStr[sizeof(mInq->ir_vendorid)] = '\0';
  80.     for (charIndex = sizeof(mInq->ir_vendorid) - 1;
  81.             charIndex > 0; charIndex--) {
  82.     if (tempStr[charIndex] == ' ') tempStr[charIndex] = '\0';
  83.     else break;
  84.     }
  85.     for ( ; charIndex > 0; charIndex--) {
  86.     if ( isupper(tempStr[charIndex]) )
  87.         tempStr[charIndex] = tolower(tempStr[charIndex]);
  88.     }
  89.     strcat(devStr, tempStr);
  90.     
  91.     /* tack on the product ID string, trimmed */
  92.     strcat(devStr, " ");
  93.     *tempStr = '\0';
  94.     strncat(tempStr, mInq->ir_productid, sizeof(mInq->ir_productid));
  95.     tempStr[sizeof(mInq->ir_productid)] = '\0';
  96.     for (charIndex = sizeof(mInq->ir_productid) - 1;
  97.             charIndex > 0; charIndex--) {
  98.     if (tempStr[charIndex] == ' ') tempStr[charIndex] = '\0';
  99.     else break;
  100.     }
  101.     strcat(devStr, tempStr);
  102.  
  103.     /* tack on the revision info, trimmed, if it's there */
  104.     if ( (mInq->ir_revision[0] != ' ') && (mInq->ir_revision[0] != '\0')) {
  105.     strcat(devStr, " (rev. ");
  106.     *tempStr = '\0';
  107.     strncat(tempStr, mInq->ir_revision, sizeof(mInq->ir_revision));
  108.     tempStr[sizeof(mInq->ir_revision)] = '\0';
  109.     for (charIndex = sizeof(mInq->ir_revision) - 1;
  110.             charIndex > 0; charIndex--) {
  111.         if (tempStr[charIndex] == ' ') tempStr[charIndex] = '\0';
  112.         else break;
  113.         }
  114.     strcat(devStr, tempStr);
  115.     strcat(devStr, ")");
  116.     }
  117.  
  118.     return mInq->ir_devicetype;
  119. }
  120.  
  121.  
  122. @end
  123.